package com.wu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by wsq547 on 2021/10/4 19:42
 */
@Controller
@RequestMapping("/admin")
public class LoginController {

    //跳转到登录页面
    @RequestMapping("/toLoginPage")
    public String toLoginPage(){
        return "login";
    }

    //登录提交
    @RequestMapping("/login")
    public String login(HttpSession session, String adminName, String password, Model model){

        String admin = "admin547";
        String psw = "123";

        System.out.println(adminName);
        System.out.println(password);


        if (adminName.equals(admin)&&password.equals(psw)) {

            //把用户的信息存到session里面
            session.setAttribute("userLoginInfo", adminName);

            System.out.println(adminName);

            model.addAttribute("userLoginInfo", adminName);
            return "redirect:/student/allStudent";
        }else {
            String msg = "账号或密码错误！";
            model.addAttribute("msg",msg);
            return "login";
        }

    }

    //返回首页
    @RequestMapping("/toIndexPage")
    public String toIndexPage(){
        return "redirect:/index.jsp";
    }

    //注销
    @RequestMapping("/goOut")
    public String goOUt(HttpSession session){
        session.removeAttribute("userLoginInfo");
        return "redirect:/index.jsp";

    }


}
